package dao;

import utils.DbUtils;

import java.sql.PreparedStatement;
import java.sql.SQLException;

public class MiddleDaoImpl extends DbUtils implements MiddleDao{
    @Override
    public int insertMiddle(Integer roleid, String[] ids) {
        String sql = "insert into middle values(null,?,?)";
        int k = 0;
        try {
            //批量新增
            preparedStatement = getPreparedStatement(sql);
            for (String id : ids) {
                preparedStatement.setInt(1,roleid);
                preparedStatement.setInt(2,Integer.parseInt(id));
                preparedStatement.addBatch();
            }
            preparedStatement.executeBatch();
            k=1;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            closeAll();
        }
        return k;
    }
}
